package com.sd.activity;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.os.Handler;
import android.widget.Button;
import android.widget.TextView;

/**
 * woa3.3测试demo基础Activity
 * 
 * @author david
 * 
 */
public class BaseActivity extends Activity {

	// 应用自己的应用ID（没有的请申请，务必保证接入时使用自己的应用ID）
	public static String appId;
	// 应用服务器url路径
	public static String appserverPath = null;
	// 本机号登陆流程（简单流程：0 复杂流程：1）
	public static String process;
	// 上下行短信
	public static String smsway;
	// 压力测试循环次数
	public static int times;

	protected double[] xValue;
	protected double[] yValue;
	protected double duration;

	// log显示控件
	protected TextView log_textView;
	// 清除、刷新、 压力测试按钮
	protected Button clearLog_btn, refresh_btn, performance_btn;
	// 登录令牌
	protected String token;
	// sessionId验证返回结果码
	protected String resultCode;
	// uuId验证码相关
	protected String uuId;
	protected Handler mHandler = new Handler();
	// 起始时间戳
	protected long startTime = System.currentTimeMillis();
	// 运行log
	protected StringBuffer log = new StringBuffer("startTime:----------------" + startTime + "---------\n");
	// 处理进程
	protected ProgressDialog mProgressDialog = null;
	// 显示log线程
	protected Runnable mShowLog = new Runnable() {
		public void run() {
			log_textView.setText(log.toString());
		}
	};

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		try {
			ApplicationInfo appi = getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA);
			Bundle bundle = appi.metaData;
			Object value = bundle.get("woa_key_appid");
			appId = value.toString();
		} catch (NameNotFoundException e) {
			appId = "9998";
		}
	}

	// ---------------- customize method -------------------
	/**
	 * 打印log到界面
	 * 
	 * @param info
	 */
	protected void printLogOnScreen(String info) {
		log.append(info);
		mHandler.post(mShowLog);
	}
}
